
import time
from faker import Faker


class Fake:
    """
    封装faker类，进行数据模拟
    """
    fake = Faker(locale='zh_CN')


    def phone_number(self):
        """
        手机号
        :return:
        """
        return self.fake.phone_number()

    def email(self):
        """
        邮箱
        :return:
        """
        return self.fake.email()

    def name(self):
        """
        姓名
        :return:
        """
        return self.fake.name()

    def address(self):
        """
        住址
        :return:
        """
        return self.fake.address()

    def company(self):
        """
        公司
        :return:
        """
        return self.fake.company()

    def job(self):
        """
        工作
        :return:
        """
        return self.fake.job()

    @property
    def text(self, length=200):
        """
        根据长度返回文本
        :return:
        """
        return self.fake.text(max_nb_chars=length)

    @property
    def date_stamp(self, length=9):
        """
        时间戳
        :return:
        """
        return self.fake.unix_time() if length == 9 else self.fake.unix_time()



    @staticmethod
    def date(pattern=1, customize=None) -> str:
        """
        根据日期模式返回不同的时间格式
        :param pattern: 返回的时间格式
        :param customize: 自定义时间格式
        :return:
        """
        if pattern == 1:
            return time.strftime("%y%m%d%H%M%S", time.localtime(time.time()))
        elif pattern == 2:
            return time.strftime("%y%m%d", time.localtime(time.time()))
        elif pattern == 3:
            return time.strftime("%y-%m-%d-%H-%M-%S", time.localtime((time.time())))
        else:
            return time.strftime(customize, time.localtime((time.time()))) if customize else False
